﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class UpgradeGUINew : MonoBehaviour
{
	//convert stuff
	private Rect windowRect = new Rect (0, 0, 120, 50);
	public static bool upgradeEnabled = false;
	public static bool onStart = true;
	
	public Texture2D normalWeaponBack;
	public Texture2D highlightWeaponBack;

	public Texture2D laserHighLight;
	public Texture2D laserHighLight2;
	public Texture2D laserHighLight3;
	public Texture2D rocketHighLight;
	public Texture2D clusterHighLight;
	public Texture2D voidHighLight;
	public Texture2D Lock;

	public	Texture2D cluster;
	public	Texture2D laser;
	public	Texture2D laser2;
	public	Texture2D laser3;
	public	Texture2D rockets;
	public	Texture2D voidicon;
	bool[] myUpgradeGroup;
	public Texture2D[] statBarArray;
	public Texture2D attackStatBar;
    public Texture2D defenseStatBar, windowBackGroundTex, hightlight, tabBackground;
	public int index;
	int fakeIndex;
	int statIndex;
	bool statGroup;
	bool buildingGroup;
	bool weaponGroup;
	bool showAttack;
	bool showDamage;
	bool showSupport;
	bool showFireRate;
	bool showArmor;
	bool showEvasion;
	bool buyMe = false;
	private WeaponPurchases Weapon;
	statMenu stat;


    public Rect WeaponBox;

    private Rect Laser;
	private Rect MultiLaser;
	private Rect ShotgunLaser;
	private Rect RocketLoc;
	private Rect ClusterLoc;
	private Rect VortexLoc;


	bool mainattack1;
	bool mainattack2;
	bool mainattack3;
	bool altattack1;
	bool altattack2;
	bool altattack3;
    public InnerWindowButtonClass content;
    private GUIStyle buttonStyle;
    public GUIStyle buttonStyle1, highlightStyle;
   public GUIStyle weaponScreenText;
   public GUIStyle yesnoWeaponBuy;
   public GUIStyle yesnoWeaponBuy1;
    public InnerWindowButtonClass Resume;
	private System.Collections.Generic.List<string> WeaponsList;

	private TKSwipeDirection swipeDir;
    public BuildingMenu[] Buildings;
	private int index2;
	private int fragments, initialFragments;
	
	public BuyWindow buyWindow;
	public WeaponPurchases multilaser, shotgunlaser, vortex, clusterbomb;
	
	// Use this for initialization
	
	[System.Serializable]
	public class WeaponPurchases
	{
		public int Cost;
		public string WeaponName;
	}
	
	[System.Serializable]
    public class BuyWindow
    {
		public Rect WindowLocation = new Rect(Screen.width/2, Screen.height/2, 200f, 200f);
		public InnerWindowButtonClass Yes, No;
    }

    [System.Serializable]
    public class InnerWindowButtonClass
    {
        public Rect ButtonLocation = new Rect(80f, 20f, 105f, 35f);
        public Texture2D Texture;
        public string Text = "If no texture use this";
    }

    [System.Serializable]
    public class BuildingMenu
    {
        public string BuildingName = "name";
        public Rect TabLocation = new Rect(80f, 20f, 105f, 35f);
        public Texture2D TabTexture;
        public string Text = "If no texture use this";
        public Rect BuildingLocation = new Rect(100f, 100f, 100f, 100f);
        public Texture2D BuildingTexture;
        public InnerWindowButtonClass PlusButton;
        public int value = 0;
        public LabelClass Title;
        public LabelClass Description;
        public string playerPrefKey = "PlayerPrefKey";
		public ValueAttr ValueAttributes;
    }
	[System.Serializable]
    public class ValueAttr
    {
        public int maxVal = 100;
        public int minVal = 0;
        public int increment = 10;
        public int Cost = 10;
    }
	
	
    [System.Serializable]
    public class LabelClass
    {
        public Rect LabelLocation = new Rect(80f, 20f, 105f, 35f);
        public string text = "Enter text here";
        public GUIStyle labelStyle;
        //public Texture2D pauseTexture;
    }

	public void swipeDetection (bool enabled)
	{
		//Swipe Detection
		var swipe = new TKSwipeRecognizer (TKSwipeDirection.Horizontal);
		swipe.gestureRecognizedEvent += (r) =>
		{
			swipeDir = r.completedSwipeDirection;
		};
		TouchKit.addGestureRecognizer (swipe);
	}
    void Start()
    {
        WeaponsList = new List<string>();
        WeaponsList.Add("Rocket");
        WeaponsList.Add("Laser");
		shipStats();
    }
	void customStart ()
	{
//		//Used to not lose data
//		multilaser.Cost = 200;
//		multilaser.WeaponName = "Multi-Laser";
//		shotgunlaser.Cost = 500;
//		shotgunlaser.WeaponName = "Shotgun-Laser";
//		vortex.WeaponName = "Vortex";
//		vortex.Cost = 1000;
//		clusterbomb.WeaponName = "Clusterbomb";
//		clusterbomb.Cost = 1000;
//		buyWindow.WindowLocation = new Rect(15.8f, 5f, 410f, 269.05f);
//		buyWindow.Yes.ButtonLocation =new Rect(68.8f, 22.9f, 105f, 35f);
//		buyWindow.No.ButtonLocation =new Rect(190.1f, 22.9f, 105f, 35f);

		   
		        initialFragments = PlayerPrefs.GetInt("Currency");
		fragments = PlayerPrefs.GetInt("Currency");
        foreach (BuildingMenu building in Buildings)
        {
           building.value = PlayerPrefs.GetInt(building.playerPrefKey);
        }
        //for (int i = 0; i < Buildings.Length; i++)
        //{
        //    Buildings[i].Title = Buildings[0].Title;
        //    Buildings[i].Description = Buildings[0].Description;
        //}
       // textStyle = new GUIStyle(GUI.skin.GetStyle("Text"));


        buttonStyle = new GUIStyle(GUI.skin.GetStyle("Button"));
        buttonStyle.normal.background = normalWeaponBack;
        buttonStyle.onNormal.background = highlightWeaponBack;

				
		windowRect = new Rect (0, 0, Screen.width, Screen.height);
		stat = gameObject.GetComponent<statMenu> ();
		myUpgradeGroup = new bool[3];
		statBarArray = new Texture2D[2];
		myUpgradeGroup [0] = false;
		myUpgradeGroup [1] = false;
		myUpgradeGroup [2] = false;
		index = 0;
		statBarArray [0] = attackStatBar;
		statBarArray [1] = defenseStatBar;

		switch (Controller.mainAttack) {
		case Controller.mainAttacks.Laser:
			mainattack1 = true;
			mainattack2 = false;
			mainattack3 = false;
			break;
		case Controller.mainAttacks.Multilaser:
			mainattack1 = false;
			mainattack2 = true;
			mainattack3 = false;
			break;
		case Controller.mainAttacks.Shottylaser:
			mainattack1 = false;
			mainattack2 = false;
			mainattack3 = true;
			break;
		default:
			mainattack1 = true;
			break;
		}
		switch (Controller.secondaryAttack) {
		case Controller.secondaryAttacks.Rocket:
			altattack1 = true;
			altattack2 = false;
			altattack3 = false;
			break;
		case Controller.secondaryAttacks.Clusterbomb:
			altattack1 = false;
			altattack2 = true;
			altattack3 = false;
			break;
		case Controller.secondaryAttacks.Vortex:
			altattack1 = false;
			altattack2 = false;
			altattack3 = true;
			break;
		default:
			altattack1 = true;
			break;
		}

	}

	void shipStats ()
	{
		//B2 Bomber is stronger and more evasive
		if (PlayerPrefs.GetString ("PlayerShip") == "B2Bomber")
        {
			PlayerPrefs.SetInt ("DamageBoost", 10);
			PlayerPrefs.SetInt ("Evasion", 20);
		}
		// Gold ship gives you more currency and higher drops

		//Random bonuses up to 10
        //if (PlayerPrefs.GetString ("PlayerShip") == "Regs") 
        //{
        //    //PlayerPrefs.SetInt("HealthBoost", Random.Range(0, 11));
        //    //PlayerPrefs.SetInt("DamageBoost", Random.Range(0, 11));
        //    //PlayerPrefs.SetInt("FireRate", Random.Range(0, 11));
        //    //PlayerPrefs.SetInt("Armor", Random.Range(0, 2));
        //    //PlayerPrefs.SetInt("Evasion", Random.Range(0, 6));
        //}

		//City Bonuses
		if (PlayerPrefs.GetString ("PlayerShip") == "ThisIsSparta") 
        {
			PlayerPrefs.SetInt ("ShieldBoost", 10);
			PlayerPrefs.SetInt ("ResidentialBoost", 10);
			PlayerPrefs.SetInt ("AttackBoost", 10);
		}
	}

	void OnGUI ()
	{
        
        WeaponBox = new Rect(Screen.width / 2 - WeaponBox.width / 2, Screen.height * .1f, Screen.width * .85f, Screen.height * .7f);

		if (onStart) 
		{
			customStart ();
			onStart = false;
		}
		if (upgradeEnabled)
        {/*
			GUI.Box(new Rect(Screen.width / 2 , Screen.height / 2 + 100, 150, 50), "500");//laser
		GUI.Box(new Rect(Screen.width / 2 , Screen.height / 2 + 100, 150, 50), "1000");//multi laser
		GUI.Box(new Rect(Screen.width / 2 , Screen.height / 2 + 100, 150, 50), "1500");//shotgun laser
		GUI.Box(new Rect(Screen.width / 2 , Screen.height / 2 + 100, 150, 50), "1000");//rockets
		GUI.Box(new Rect(Screen.width / 2 , Screen.height / 2 + 100, 150, 50), "2000");//cluster bomb
		GUI.Box(new Rect(Screen.width / 2 , Screen.height / 2 + 100, 150, 50), "3000");//void
          * 
		*/
			swipeDetection (true);
            GUIStyle style = new GUIStyle(GUI.skin.GetStyle("Window")); //Or whatever
            style.onNormal = style.normal;
            windowRect = new Rect(windowRect.x, windowRect.y, Screen.width, Screen.height); 
           
            GUI.DrawTexture(windowRect, windowBackGroundTex);
            GUI.Box(windowRect, "");
			windowRect = GUI.Window (0, windowRect, DoWork, "", style);
            if (buyMe)
            {
                GUI.ModalWindow(1, new Rect(Screen.width / buyWindow.WindowLocation.x - buyWindow.WindowLocation.width / 2, WeaponBox.y + WeaponBox.height/2 - buyWindow.WindowLocation.height/2, buyWindow.WindowLocation.width, buyWindow.WindowLocation.height), BuyWindowWork, "Purchase " + Weapon.WeaponName + " for " + Weapon.Cost + "?", yesnoWeaponBuy);
            }

		}

	}

	IEnumerator PauseResume (float wait)
	{
		Time.timeScale = 0.00000001f;
		float pauseEndTime = Time.realtimeSinceStartup + .01f;
		while (Time.realtimeSinceStartup < pauseEndTime) 
        {
			yield return 0;
		}
		Time.timeScale = 1;
		Controller.shootSecondary = true;
	}
	public void ResumeTest()
	{
		Controller.shootSecondary = true;
	}
    			
	public void BuyWindowWork(int windowID)
		{
		//GUI.BeginGroup(new Rect(Screen.width/buyWindow.WindowLocation.x, Screen.height/buyWindow.WindowLocation.y, buyWindow.WindowLocation.width, buyWindow.WindowLocation.height));
            if (GUI.Button(buyWindow.Yes.ButtonLocation, "Yes", yesnoWeaponBuy))
			{
			    fragments = PlayerPrefs.GetInt("Currency");
				if(fragments >= Weapon.Cost)
				{
					fragments -= Weapon.Cost;
					WeaponsList.Add(Weapon.WeaponName);
                    if (WeaponsList.Count == 3)
                    {
                        GameCenterSingleton.Instance.AddAchievementProgress("Weapon_1", 100f);
                    }
					PlayerPrefs.SetInt("Currency", fragments);
					buyMe = false;
				}
			}

            if (GUI.Button(buyWindow.No.ButtonLocation, "No", yesnoWeaponBuy))
			{
				buyMe = false;
			}
		//GUI.EndGroup();
		}	
	public void DoWork (int windowID)
	{
		
		myUpgradeGroup [index] = false;
		if (swipeDir == TKSwipeDirection.Left) 
        {
			index = (++index) % myUpgradeGroup.Length;
			swipeDir = TKSwipeDirection.All;
		}
		if (swipeDir == TKSwipeDirection.Right) 
        {
			if (index > 0) 
            {
				index = (--index) % myUpgradeGroup.Length;
			} else
				index = myUpgradeGroup.Length - 1;
			swipeDir = TKSwipeDirection.All;
		}
		myUpgradeGroup [index] = true;
		
		if (myUpgradeGroup [0]) 
        {
			buyMe =false;
			statIndex = 0;
            //GUI.BeginGroup (new Rect (Screen.width / 2 - 400, Screen.height / 2 - 200, 800, 800));
			stat.DoGUI ();                    
            //GUI.EndGroup ();
		}
		 
		if (myUpgradeGroup [1]) 
        {
			buyMe = false;
			GUIStyle labelStyle = new GUIStyle(GUI.skin.GetStyle("label"));
			labelStyle.fontSize = 60;
			labelStyle.font = weaponScreenText.font;
			labelStyle.contentOffset = Vector2.zero;
			labelStyle.normal.textColor = Color.white;
			labelStyle.alignment = TextAnchor.MiddleCenter;
			GUI.Label(new Rect(0, 0, Screen.width, Screen.height * .2f), "City Boosts", labelStyle);
            Rect buildingback = new Rect(Screen.width/2 - Screen.width*.9f/2, Screen.height*.3f, Screen.width*.9f, Screen.height*.5f);
            GUI.DrawTexture(buildingback, content.Texture);
            GUI.Box(buildingback, "");

            ////
			//GUI.BeginGroup (new Rect (Screen.width / 2 - 200, Screen.height / 2 - 200, 800, 800));
		
            //GUI.Box (new Rect (0, 0, 400, 400), "BUILDINGS");
            //GUI.Box (new Rect (0, 20, 200, 200), BuildingIcons[0]);
            //GUI.Box (new Rect (0, 120, 200, 200), BuildingIcons[1]);
            //GUI.Box (new Rect (0, 220, 200, 200), BuildingIcons[2]);
            var boxOutline = new GUIStyle();
            boxOutline.normal.background = tabBackground;
            
            //Button
            for (int i = 0; i < Buildings.Length; i++)
            {
                Rect tabs = new Rect(buildingback.x, buildingback.y - buildingback.height, buildingback.width / 3, Screen.height * .15f);
                tabs = new Rect(buildingback.x + tabs.width * i, buildingback.y - tabs.height, buildingback.width / 3, Screen.height * .15f);
                
                GUI.DrawTexture(tabs, Buildings[i].TabTexture, ScaleMode.StretchToFill);
                if (Buildings[i].TabTexture == null ? GUI.Button(tabs, Buildings[i].Text) : GUI.Button(tabs, "", boxOutline))
                {
                    index2 = i;
                }

            }
            highlightStyle.normal.background = hightlight;
            GUI.color = new Color(1, 1, 1, .6f);
            highlightStyle.border = new RectOffset(3, 3, 3, 3);
            Rect tabs2 = new Rect(buildingback.x, buildingback.y - buildingback.height, buildingback.width / 3, Screen.height * .15f);
            tabs2 = new Rect(buildingback.x + tabs2.width * index2, buildingback.y - tabs2.height, buildingback.width / 3, Screen.height * .15f);

            GUI.Box(tabs2, "", highlightStyle);
            GUI.color = new Color(1, 1, 1, 1);


            float ValueBoxH = buildingback.height * .5f;
            float ValueBoxW = buildingback.width * .6f;

            Rect ValueBox = new Rect(buildingback.x + buildingback.width / 2 - ValueBoxW / 2, buildingback.y + buildingback.height * .45f - ValueBoxH / 2, ValueBoxW, ValueBoxH);


            GUI.DrawTexture(new Rect(ValueBox.x, ValueBox.y + ValueBox.height, ValueBox.width, Buildings[index2].value / 100f * -226), Buildings[index2].BuildingTexture, ScaleMode.StretchToFill);
            GUI.Box(ValueBox, "");

            if (GUI.Button(new Rect(buildingback.x + buildingback.width/2 - Buildings[index2].PlusButton.ButtonLocation.width/2, buildingback.y + buildingback.height*.85f - Buildings[index2].PlusButton.ButtonLocation.height/2, Buildings[index2].PlusButton.ButtonLocation.width, Buildings[index2].PlusButton.ButtonLocation.height), Buildings[index2].PlusButton.Texture) && fragments > 0 && fragments >= Buildings[index2].ValueAttributes.Cost)
            {
	            if (Buildings[index2].value < Buildings[index2].ValueAttributes.maxVal)
	            {
					Buildings[index2].value += Buildings[index2].ValueAttributes.increment;
	                fragments -= Buildings[index2].ValueAttributes.Cost;
					PlayerPrefs.SetInt("Currency", fragments);
	                PlayerPrefs.SetInt(Buildings[index2].playerPrefKey, Buildings[index2].value);
	                print(Buildings[index2].playerPrefKey);
	            }
                
            }
			        if (Buildings[index2].value > Buildings[index2].ValueAttributes.maxVal)
            Buildings[index2].value = Buildings[index2].ValueAttributes.maxVal;
			
            Buildings[0].Title.labelStyle.normal.textColor = Color.green;
            Rect title = new Rect(0,0,buildingback.width, buildingback.height*.1f);
            title = new Rect(buildingback.x + buildingback.width / 2 - title.width / 2, buildingback.y, title.width, title.height);
            Rect desc = new Rect(0,0,buildingback.width, buildingback.height*.1f);
            desc = new Rect(buildingback.x + buildingback.width / 2 - title.width / 2, title.y + title.height, title.width, title.height);
            Buildings[index2].Title.labelStyle.contentOffset = Vector2.zero;
            Buildings[index2].Description.labelStyle.contentOffset = Vector2.zero;
            Buildings[index2].Title.labelStyle.alignment = TextAnchor.MiddleCenter;
            Buildings[index2].Description.labelStyle.alignment = TextAnchor.MiddleCenter;
            //Buildings[index2].Description.labelStyle.wordWrap = true;
            GUI.Label(title, Buildings[index2].Title.text, Buildings[index2].Title.labelStyle);
            GUI.Label(desc, Buildings[index2].Description.text, Buildings[index2].Description.labelStyle);
		}
		
		if (myUpgradeGroup [2]) 
        {

            
            Laser = new Rect(WeaponBox.width / 2 - Laser.width / 2 - WeaponBox.width * .25f, WeaponBox.height * .20f, WeaponBox.width * .4f, WeaponBox.height * .2f);
            
            MultiLaser = new Rect(WeaponBox.width / 2 - MultiLaser.width / 2 - WeaponBox.width * .25f, Laser.y + Laser.height + WeaponBox.height * .05f, WeaponBox.width * .4f, WeaponBox.height * .2f);
            ShotgunLaser = new Rect(WeaponBox.width / 2 - ShotgunLaser.width / 2 - WeaponBox.width * .25f, MultiLaser.y + MultiLaser.height + WeaponBox.height * .05f, WeaponBox.width * .4f, WeaponBox.height * .2f);

            
            RocketLoc = new Rect(WeaponBox.width / 2 - RocketLoc.width / 2 + WeaponBox.width * .25f, WeaponBox.height * .20f, WeaponBox.width * .4f, WeaponBox.height * .2f);
            ClusterLoc = new Rect(WeaponBox.width / 2 - ClusterLoc.width / 2 + WeaponBox.width * .25f, RocketLoc.y + RocketLoc.height + WeaponBox.height * .05f, WeaponBox.width * .4f, WeaponBox.height * .2f);
            VortexLoc = new Rect(WeaponBox.width / 2 - VortexLoc.width / 2 + WeaponBox.width * .25f, ClusterLoc.y + ClusterLoc.height + WeaponBox.height * .05f, WeaponBox.width * .4f, WeaponBox.height * .2f);
            
            
            
            
            GUI.DrawTexture(WeaponBox, content.Texture);
            weaponScreenText.fontSize = 60;
            //GUI.Box (WeaponBox, "Weapons", weaponScreenText);

            GUI.BeginGroup(WeaponBox, "Weapons", weaponScreenText);
			Texture2D bLaser, bLaser2, bLaser3, bRocket, bClusterbomb, bVortex;
			bLaser = laser;
			bLaser2 = laser2;
			bLaser3 = laser3;
            bRocket = rockets;
            bClusterbomb = cluster;
            bVortex = voidicon;
			
            mainattack1 = GUI.Toggle(Laser, mainattack1, bLaser, buttonStyle);

            if (mainattack1 && WeaponsList.Contains("Laser"))
            {
                bLaser = laserHighLight;
                mainattack1 = true;
                mainattack2 = false;
                mainattack3 = false;
            }
            else
            {
                if (!mainattack2 && !mainattack3)
                    mainattack1 = true;
            }
            
			mainattack2 = GUI.Toggle(MultiLaser, mainattack2, bLaser2, buttonStyle);
			if(WeaponsList.Contains(multilaser.WeaponName) == false)
			{
				GUI.DrawTexture(MultiLaser, Lock);
			}
			if(mainattack2)
			{
				if(WeaponsList.Contains(multilaser.WeaponName))
				{
					bLaser2 = laserHighLight2;
					mainattack1 = false;
					mainattack2 = true;
					mainattack3 = false;
				}
				else
				{
					Weapon = multilaser;
					buyMe = true;
				}
			}
			else
			{
				bLaser2 = laser2;
                if (!mainattack1 && !mainattack3)
                    mainattack2 = true;
			}

            mainattack3 = GUI.Toggle(ShotgunLaser, mainattack3, bLaser3, buttonStyle);
			if(WeaponsList.Contains(shotgunlaser.WeaponName) == false)
			{
				GUI.DrawTexture(ShotgunLaser, Lock);
			}
			
			if(mainattack3)
			{
				if(WeaponsList.Contains(shotgunlaser.WeaponName))
				{
					bLaser3 = laserHighLight3;
					mainattack1 = false;
					mainattack2 = false;
					mainattack3 = true;
				}
				else
				{
					Weapon = shotgunlaser;
					buyMe = true;
				}
			}
			else
			{
				bLaser3 = laser3;
                if (!mainattack1 && !mainattack2)
                    mainattack3 = true;
			}
            altattack1 = GUI.Toggle(RocketLoc, altattack1, bRocket, buttonStyle);
            if (altattack1)
            {
                bRocket = rocketHighLight;
                altattack1 = true;
                altattack2 = false;
                altattack3 = false;
            }
            else 
            {
                bRocket = rockets;
                if (!altattack2 && !altattack3)
                    altattack1 = true;
            }
			
	
            altattack2 = GUI.Toggle(ClusterLoc, altattack2, bClusterbomb, buttonStyle);
			if(WeaponsList.Contains(clusterbomb.WeaponName) == false)
			{
				GUI.DrawTexture(ClusterLoc, Lock);
			}
			if (altattack2) 
            {
				if(WeaponsList.Contains(clusterbomb.WeaponName))
				{
					bClusterbomb = clusterHighLight;
               	 	altattack1 = false;
                	altattack2 = true;
            	    altattack3 = false;
				}
				else
				{
					Weapon = clusterbomb;
					buyMe = true;
				}
            }
            else
            {
                bClusterbomb = cluster;
                if (!altattack1 && !altattack3)
                    altattack2 = true;
			}

			
            altattack3 = GUI.Toggle(VortexLoc, altattack3, bVortex, buttonStyle);
			if(WeaponsList.Contains(vortex.WeaponName) == false)
			{
				GUI.DrawTexture(VortexLoc, Lock);
			}
            if (altattack3)
            {
				if(WeaponsList.Contains(vortex.WeaponName))
				{
					bVortex = voidHighLight;
	                altattack1 = false;
	                altattack2 = false;
	                altattack3 = true;
				}
				else
				{
					Weapon = vortex;
					buyMe = true;
				}
            }
            else
            {
                bVortex = voidicon;
                if (!mainattack1 && !mainattack2)
                    mainattack3 = true;
            }
            //GUIStyle labelStyle = new GUIStyle();
            GUIStyle labelStyle = new GUIStyle(GUI.skin.GetStyle("label"));
            labelStyle.fontSize = 40;
            labelStyle.font = weaponScreenText.font;
            labelStyle.contentOffset = Vector2.zero;
            labelStyle.normal.textColor = Color.black;
			labelStyle.alignment = TextAnchor.MiddleCenter;
            GUI.Box(new Rect(Laser.x, Laser.y - Laser.height / 2 - Laser.height*.2f, Laser.width, Laser.height), "Primary", labelStyle);
            GUI.Box(new Rect(RocketLoc.x, RocketLoc.y - RocketLoc.height / 2 - RocketLoc.height * .2f, RocketLoc.width, RocketLoc.height), "Secondary", labelStyle);
        GUI.EndGroup();

		}
        Resume.ButtonLocation.height = Screen.height * .14f;
        Resume.ButtonLocation.width = Screen.width * .8f;
        var resumeRect = new Rect(Screen.width / 2 - Resume.ButtonLocation.width / 2, Screen.height * .9f - Resume.ButtonLocation.height / 2, Resume.ButtonLocation.width, Resume.ButtonLocation.height);
        GUI.DrawTexture(resumeRect, Resume.Texture);
		if (GUI.Button (resumeRect, Resume.Text, buttonStyle1)) 
        {
			if (mainattack1)
				Controller.mainAttack = Controller.mainAttacks.Laser;
			if (mainattack2)
				Controller.mainAttack = Controller.mainAttacks.Multilaser;
			if (mainattack3)
				Controller.mainAttack = Controller.mainAttacks.Shottylaser;
			if (altattack1)
				Controller.secondaryAttack = Controller.secondaryAttacks.Rocket;
			if (altattack2)
				Controller.secondaryAttack = Controller.secondaryAttacks.Clusterbomb;
			if (altattack3)
				Controller.secondaryAttack = Controller.secondaryAttacks.Vortex;

            foreach (BuildingMenu building in Buildings)
            {
                PlayerPrefs.SetInt(building.playerPrefKey, building.value);
            }

			StartCoroutine (PauseResume (.5f));
			TouchKit.removeAllGestureRecognizers ();
			Manager.WaveResume (0);
			//Time.timeScale = 1;
			//Invoke("ResumeTest", 1f);
		}
	}
}

